Skip to content

builder/azure-arm: Remove duplicate resource deletion steps#9559

Merged
SwampDragons merged 7 commits intomasterfrom
fix_9482
Aug 12, 2020
Merged

builder/azure-arm: Remove duplicate resource deletion steps#9559
SwampDragons merged 7 commits intomasterfrom
fix_9482

Conversation

@nywilken
Copy link
Copy Markdown
Contributor

@nywilken nywilken commented Jul 9, 2020

This change removes StepDeleteResourceGroup from the ARM builder. The StepDeleteResourceGroup step was a combination of StepCreateResourceGroup#Cleanup and StepDeployTemplate#Cleanup. Which was causing soft errors on cleanup because the Azure builder was trying to access resources in the step cleanup functions that were deleted by StepDeleteResourceGroup.

This change also removes the StepDeleteOSDisk and modifies the StepDeleteAdditionalDisk steps as they were found to be only working when the StepDeleteResourceGroup was being executed. More specifically, the DeleteResourceGroup step was deleting all deployment operations including the resource group associated with the build so the additional delete steps were essentially a noop. After removing the call to the DeleteResourceGroup step the following error was being thrown

Build 'azure-arm' errored: storage: service returned error: StatusCode=412, ErrorCode=LeaseIdMissing, ErrorMessage=There is currently a lease on the blob and no lease ID was specified in the request.                                                                                               
RequestId:05c17014-101e-0027-7218-704428000000
Time:2020-08-11T19:46:04.6437683Z, RequestInitiated=Tue, 11 Aug 2020 19:46:04 GMT, RequestId=05c17014-101e-0027-7218-704428000000, API Version=2018-03-28, QueryParameterName=, QueryParameterValue=                                                                                                  

#Closes #9482

Build Results Before Change

VHD basic build
==> azure-arm: The resource group was created by Packer, deleting ...
==> azure-arm: Deleting the temporary OS disk ...
==> azure-arm:  -> OS Disk : skipping, managed disk was used...
==> azure-arm: Deleting the temporary Additional disk ...
==> azure-arm:  -> Additional Disk : skipping, managed disk was used...
==> azure-arm: Removing the created Deployment object: 'pkrdpxze28l7mdu'
==> azure-arm: ERROR: -> ResourceGroupNotFound : Resource group 'pkr-Resource-Group-xze28l7mdu' could not be found.
==> azure-arm:
==> azure-arm: Removing the created Deployment object: 'kvpkrdpxze28l7mdu'
==> azure-arm: ERROR: -> ResourceGroupNotFound : Resource group 'pkr-Resource-Group-xze28l7mdu' could not be found.
==> azure-arm:
Build 'azure-arm' finished.

Build results after change

Regression suite run, after change
RUNNING: /home/wilken/Development/regression-suite/regressions/output/c6a9ea41-4c7a-4cd2-a182-2dc716cef101/azure-test-1.json                      
checking logfile /home/wilken/Development/regression-suite/regressions/output/c6a9ea41-4c7a-4cd2-a182-2dc716cef101/packer_log_azure-test-1.txt    
searching for Welcome to PACKER
PASS: Found stdout "Welcome to PACKER" in logfile
searching for HELLO NEW USER; automatically generated aws password is:
PASS: Found stdout "HELLO NEW USER; automatically generated aws password is:" in logfile                                                          
searching for linuxBashScript
PASS: Found stdout "linuxBashScript" in logfile
searching for linuxBashInline
PASS: Found stdout "linuxBashInline" in logfile
searching for What is your name?
PASS: Found stdout "What is your name?" in logfile
searching for ['packer custom restart']
PASS: Found stdout "packer custom restart" in logfile
searching for ['""', 'whee']
PASS: Found stdout """" in logfile
PASS: Found stdout "whee" in logfile
searching for UnixBashScript
PASS: Found stdout "UnixBashScript" in logfile
Custom Key Vault Test
==> azure-arm: Deleting the temporary Additional disk ...
==> azure-arm: 
==> azure-arm: The resource group was not created by Packer, deleting individual resources ...                                                    
==> azure-arm:  -> Deployment Resources within: pkrdp0dhkz0nm7c
==> azure-arm:  -> Microsoft.Compute/virtualMachines : 'pkrvm0dhkz0nm7c'
==> azure-arm:  -> Microsoft.Network/networkInterfaces : 'pkrni0dhkz0nm7c'                                                                        
==> azure-arm:  -> Microsoft.Network/publicIPAddresses : 'pkrip0dhkz0nm7c'                                                                        
==> azure-arm:  -> Microsoft.Network/virtualNetworks : 'pkrvn0dhkz0nm7c'
==> azure-arm:  -> image : 'https://wilkentestpkr.blob.core.windows.net/images/pkros0dhkz0nm7c.vhd'                                               
==> azure-arm: Removing the created Deployment object: 'pkrdp0dhkz0nm7c'
==> azure-arm: 
==> azure-arm: The resource group was not created by Packer, not deleting ...                                                                     
Build 'azure-arm' finished.

==> Builds finished. The artifacts of successful builds are:
--> azure-arm: Azure.ResourceManagement.VMImage:
Additional Disk Test
==> azure-arm: Deleting the temporary Additional disk ...                                                                                          
==> azure-arm:  -> Additional Disk 1: 'https://wilkentestpkr.blob.core.windows.net/images/pkrdd0yxg9kkpm3-1.vhd'                                   
==> azure-arm:  -> Additional Disk 2: 'https://wilkentestpkr.blob.core.windows.net/images/pkrdd0yxg9kkpm3-2.vhd'                                   
==> azure-arm:                                                                                                                                     
==> azure-arm: The resource group was not created by Packer, deleting individual resources ...                                                     
==> azure-arm:  -> Deployment Resources within: pkrdp0yxg9kkpm3                                                                                    
==> azure-arm:  -> Microsoft.Compute/virtualMachines : 'pkrvm0yxg9kkpm3'                                                                           
==> azure-arm:  -> Microsoft.Network/networkInterfaces : 'pkrni0yxg9kkpm3'                                                                         
==> azure-arm:  -> Microsoft.Network/publicIPAddresses : 'pkrip0yxg9kkpm3'                                                                         
==> azure-arm:  -> Microsoft.Network/virtualNetworks : 'pkrvn0yxg9kkpm3'                                                                           
==> azure-arm:  -> image : 'https://wilkentestpkr.blob.core.windows.net/images/pkros0yxg9kkpm3.vhd'                                                
==> azure-arm: Removing the created Deployment object: 'pkrdp0yxg9kkpm3'                                                                           
==> azure-arm: 
==> azure-arm: The resource group was not created by Packer, deleting individual resources ...                                                    
==> azure-arm:  -> Deployment Resources within: kvpkrdp0yxg9kkpm3
==> azure-arm:  -> Microsoft.KeyVault/vaults/secrets : 'pkrkv0yxg9kkpm3/packerKeyVaultSecret'                                                     
==> azure-arm:  -> Microsoft.KeyVault/vaults : 'pkrkv0yxg9kkpm3'
==> azure-arm: Removing the created Deployment object: kvpkrdp0yxg9kkpm3'
Manged Disk Build
==> azure-arm: Deleting the temporary Additional disk ...
==> azure-arm:  -> Additional Disk : skipping, managed disk was used...
==> azure-arm: Removing the created Deployment object: 'pkrdpq0qhdjt7e7'
==> azure-arm: Removing the created Deployment object: 'kvpkrdpq0qhdjt7e7'                                                                        
==> azure-arm: 
==> azure-arm: Cleanup requested, deleting resource group ...
==> azure-arm: Resource group has been deleted.
Build 'azure-arm' finished.

Todos

  • Check that the reordering doesn't break the builder
  • Validate that all resources are properly deleted upon a successful build
  • Validate that build cancellations cleanup as expected
  • Move all deletion code into the actual cleanup method; refactoring out any unnecessary code.

@nywilken nywilken requested a review from paulmey as a code owner July 9, 2020 17:40
@nywilken nywilken added builder/azure tech-debt Issues and pull requests related to addressing technical debt or improving the codebase labels Jul 9, 2020
@codecov
Copy link
Copy Markdown

codecov bot commented Jul 9, 2020

Codecov Report

Merging #9559 into master will increase coverage by 0.24%.
The diff coverage is 0.00%.

Impacted Files Coverage Δ
builder/azure/arm/builder.go 10.76% <ø> (+0.09%) ⬆️
builder/azure/arm/step_create_resource_group.go 46.15% <0.00%> (+8.65%) ⬆️
builder/azure/arm/step_get_additional_disks.go 55.31% <0.00%> (-3.78%) ⬇️
builder/azure/arm/step_get_os_disk.go 51.16% <0.00%> (-3.84%) ⬇️
command/validate.go 42.85% <0.00%> (-4.14%) ⬇️
post-processor/vsphere/post-processor.go 18.04% <0.00%> (-4.12%) ⬇️
builder/googlecompute/config.go 75.27% <0.00%> (-2.78%) ⬇️
builder/vagrant/builder.go 32.75% <0.00%> (-2.70%) ⬇️
provisioner/file/provisioner.go 55.71% <0.00%> (-2.62%) ⬇️
builder/vmware/common/hw_config.go 59.53% <0.00%> (-2.32%) ⬇️
... and 86 more

@nywilken nywilken marked this pull request as draft July 9, 2020 17:56
@nywilken nywilken force-pushed the fix_9482 branch 2 times, most recently from 115c2ba to 473b104 Compare August 11, 2020 20:28
@nywilken nywilken marked this pull request as ready for review August 12, 2020 16:14
@nywilken nywilken requested a review from a team August 12, 2020 16:14
@nywilken nywilken added this to the 1.6.2 milestone Aug 12, 2020
Copy link
Copy Markdown
Contributor

@SwampDragons SwampDragons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, awesome job sorting through all of this and cleaning it up. I ran tests against my windows and linux configs and it all seemed to work as expected. :shipit: 🎉

return
} else {
ui.Say("\nCleanup requested, deleting resource group ...")
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup.

func (s *StepDeleteAdditionalDisk) deleteBlob(storageContainerName string, blobName string) error {
blob := s.client.BlobStorageClient.GetContainerReference(storageContainerName).GetBlobReference(blobName)
err := blob.Delete(nil)
_, err := blob.BreakLease(nil)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

"Error: %s", imageName, err))
}
}
return blob.Delete(nil)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is simplified!

@SwampDragons SwampDragons merged commit e97c56d into master Aug 12, 2020
@SwampDragons SwampDragons deleted the fix_9482 branch August 12, 2020 19:43
@ghost
Copy link
Copy Markdown

ghost commented Sep 12, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Sep 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tech-debt Issues and pull requests related to addressing technical debt or improving the codebase track-internal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResourceGroupNotFound Resource group pkr-Resource-Group- could not be found

2 participants